package com.xxx.coll;

import java.util.HashSet;
import java.util.Iterator;

/**
 * @version v1.0
 * @Description:
 * @Author zhanzhongxin
 * @Date 2021/7/20 16:15
 * @Copyright 博为峰
 */
public class HashSetDemo {
    public static void main(String[] args) {
        /*
           HashSet存储数据
           1.先判断对象的hashCode值
             不同，不再判断equals方法，直接存储
             相同，再判断equals方法，如果相同不存，不同则存储
         */
        HashSet hashSet = new HashSet();
        hashSet.add(new Worker("张三",20));
        hashSet.add(new Worker("李四",30));
        hashSet.add(new Worker("王五",50));
        hashSet.add(new Worker("王五",50));
        Iterator iterator = hashSet.iterator();
        while (iterator.hasNext()){
            Worker worker = (Worker)iterator.next();
            System.out.println(worker.getName());
        }

    }
}
